
package game;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.io.File;
import java.io.IOException;

import system.*;

public class GameOver extends Scene{

	AnimatedSprite overlay, ok, background, background2, text;
	Actor bg1a, bg1b, okguy;

	int alphaIndex = 0;

	public GameOver(Game aGame, InputManager IM, SoundLibrary jukebox) {
		super(aGame, IM, jukebox);
		try {
			overlay = new AnimatedSprite(new File("assets/sprites/gameover-overlay.png"), 480, 270, false, 0);
			text = new AnimatedSprite(new File("assets/sprites/gameover-youfail.png"), 245, 57, false, 0);
			ok = new AnimatedSprite(new File("assets/sprites/gameover-ok.png"), 273, 270, false, 0);
			background = new AnimatedSprite(new File("assets/sprites/gameover-stars.png"), 480, 270, false, 0);
			background2 = new AnimatedSprite(new File("assets/sprites/gameover-stars.png"), 480, 270, false, 0);
		} catch (IOException e) {
			System.out.println("Cannot load AnimatedSprite assets");
		}

		bg1a = new Actor("Parallax", background, 0, 0, -1, 0, 0);
		bg1b = new Actor("Parallax", background2, 480, 0, -1, 0, 0);
		okguy = new Actor("Okay", ok, 280F, 0F, 0F, 0F, 0, -1);



	}

	@Override
	public void paint(Graphics g){

		Graphics2D g2d = (Graphics2D)g;

		g2d.setColor(new Color(2,3,12));
		g2d.fillRect(0, 0, 480, 270);

		g2d.drawImage(bg1a.getImage(),bg1a.getX(),bg1a.getY(), getGame());
		g2d.drawImage(bg1b.getImage(),bg1b.getX(),bg1b.getY(), getGame());

		g2d.drawImage(overlay.getImage(), 0, 0, getGame());
		
		g2d.drawImage(text.getImage(),20,50, getGame());
		
		g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alphaIndex * 0.02f));
		g2d.drawImage(okguy.getImage(), okguy.getX(), okguy.getY(), getGame());
		
	}

	@Override
	public void update(){
		bg1a.update();
		bg1b.update();
		
		if(alphaIndex < 50){
			alphaIndex++;
		}
		else{
			if(inputs.isPressing(inputs.KEY_CANCEL)){
				jukebox.Play("cursor.wav");
				game.setState(Game.GAME_START);
				inputs.handledKey(inputs.KEY_CANCEL);
			}
		}
	}

}
